package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.bifang.module.base.common.vo.excel.ExcelReadVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.core.utils.ExcelFileUtil;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduPrivateAppointStudent.EduPrivateAppointStudentKeyVO;
import com.jwsoft.manager.common.vo.eduPrivateAppointStudent.EduPrivateAppointStudentQueryVO;
import com.jwsoft.manager.common.vo.eduPrivateAppointStudent.EduPrivateAppointStudentVO;
import com.jwsoft.manager.core.integration.EduPrivateAppointStudentIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * 民办直升班名单表网关
 *
 * @author wangtao
 * @since 2022-12-16
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "民办直升班名单表", description = "民办直升班名单表")
public class EduPrivateAppointStudentController {

    @Autowired
    public EduPrivateAppointStudentIntegration eduPrivateAppointStudentIntegration;

    @Operation(summary = "民办直升班名单表分页查询",description = "民办直升班名单表分页查询")
    @PostMapping(value = "/eduPrivateAppointStudent0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduPrivateAppointStudentVO>> getList(@RequestBody @Validated EduPrivateAppointStudentQueryVO vo) {
        return AppResponse.successData(eduPrivateAppointStudentIntegration.getList(vo));
    }

    @Operation(summary = "民办直升班名单表根据主键查询详情",description = "民办直升班名单表根据主键查询详情")
    @PostMapping(value = "/eduPrivateAppointStudent0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduPrivateAppointStudentVO> getById(@RequestBody @Validated EduPrivateAppointStudentKeyVO vo) {
        return AppResponse.successData(eduPrivateAppointStudentIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "民办直升班名单表新增",description = "民办直升班名单表新增")
    @PostMapping(value = "/eduPrivateAppointStudent0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduPrivateAppointStudentVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduPrivateAppointStudentVO vo) {
        return AppResponse.successData(eduPrivateAppointStudentIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "民办直升班名单表修改",description = "民办直升班名单表修改")
    @PostMapping(value = "/eduPrivateAppointStudent0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduPrivateAppointStudentVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduPrivateAppointStudentVO vo) {
        return AppResponse.successData(eduPrivateAppointStudentIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "民办直升班名单表删除",description = "民办直升班名单表删除")
    @PostMapping(value = "/eduPrivateAppointStudent0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduPrivateAppointStudentKeyVO vo) {
        eduPrivateAppointStudentIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "民办直升班名单上传",description = "民办直升班名单上传")
    @NoSignCrypto
    @PostMapping(value = "/eduPrivateAppointStudent0007", produces = "application/json;charset=UTF-8")

    public AppResponse<ExcelReadVO> readByCode(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            HttpServletResponse response) throws IOException {
        ExcelVO vo= ExcelFileUtil.getExcelVO(request,response,paramMap);

        EduPrivateAppointStudentVO appVo = new EduPrivateAppointStudentVO();
        if (paramMap.get("schoolId") != null) {
            appVo.setSchoolId(paramMap.get("schoolId").toString());
        }
        if (paramMap.get("areaCode") != null) {
            appVo.setSchoolId(paramMap.get("areaCode").toString());
        }

        MultipartFile file=ExcelFileUtil.getExcelFile(request);
        return AppResponse.successData(eduPrivateAppointStudentIntegration.readExcel(vo, file,appVo));
    }


}
